package com.millioncool.selfpagingsimple;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class MainActivity extends AppCompatActivity {
    RecyclerView rvList;
    MainPagingAdapter adapter;
    MainViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(App.instance).create(MainViewModel.class);
        viewModel.init();
        initView();
    }

    private void initView() {
        rvList = findViewById(R.id.rv_list);
        rvList.setItemAnimator(null);
        rvList.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MainPagingAdapter(this);
        rvList.setAdapter(adapter);


        viewModel.pagingLiveData.observe(this, baseItemBeanPagingPager -> adapter.submitList(baseItemBeanPagingPager, viewModel.pagingPager));
    }
}